{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from tqdm import tqdm\n",
    "import re\n",
    "from sklearn.feature_extraction.text import TfidfVectorizer\n",
    "from sklearn.model_selection import train_test_split\n",
    "from nltk.corpus import stopwords\n",
    "from nltk.stem import SnowballStemmer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                              Sentence  polit  Unnamed: 2\n",
      "0    President Joe Biden signed an executive order ...      2         NaN\n",
      "1    but even as he signed it, the White House ackn...      2         NaN\n",
      "2    That attack, which temporarily shut down the p...      2         NaN\n",
      "3    caused gas stations to run dry and gas prices ...      2         NaN\n",
      "4    Instead, officials described the order -- mont...      2         NaN\n",
      "..                                                 ...    ...         ...\n",
      "296  according to a CNN review of court documents a...      2         NaN\n",
      "297  Earlier this month, federal prosecutors also c...      2         NaN\n",
      "298  The FBI had been seeking Warnagiris' identity,...      2         NaN\n",
      "299  The Justice Department said in charging docume...      2         NaN\n",
      "300  which led investigators to go to his military ...      2         NaN\n",
      "\n",
      "[301 rows x 3 columns]\n",
      "2751\n",
      "93\n",
      "76\n",
      "------\n",
      "3132\n",
      "169\n",
      "0\n",
      "0\n",
      "res                                                Sentence  SUBJpolit\n",
      "0     Biden issues warning to gas station owners on ...          2\n",
      "1     The company said its team \"worked safely and t...          2\n",
      "2     Republican governors are refusing aid from Dem...          2\n",
      "3     Democrats in Washington have approved trillion...          2\n",
      "4      but Republican state officials are pulling ba...          2\n",
      "...                                                 ...        ...\n",
      "1398  Stefanik has signaled to some colleagues that ...          2\n",
      "1399  Gohmert downplays January 6 riot in speech fro...          2\n",
      "1400  Republican Rep. Louie Gohmert of Texas took to...          2\n",
      "1401  Biden signs cybersecurity executive order, tho...          2\n",
      "1402  President Joe Biden signed an executive order ...          2\n",
      "\n",
      "[1403 rows x 2 columns]\n",
      "target_origin                                                Sentence  SUBJpolit\n",
      "0     Biden issues warning to gas station owners on ...          2\n",
      "1     The company said its team \"worked safely and t...          2\n",
      "2     Republican governors are refusing aid from Dem...          2\n",
      "3     Democrats in Washington have approved trillion...          2\n",
      "4      but Republican state officials are pulling ba...          2\n",
      "...                                                 ...        ...\n",
      "4699  not honorable military veterans because an hon...          1\n",
      "4700                     that line has now been crossed          1\n",
      "4701                                   watch more above          1\n",
      "4702  show us how its done excia interrogator blasts...          1\n",
      "4703  show us how its done excia interrogator blasts...          2\n",
      "\n",
      "[4704 rows x 2 columns]\n",
      "                                               Sentence  SUBJpolit\n",
      "2304  cypherpunks freedom a… julian assange best pri...          2\n",
      "3282  he’s even supposedly considering settling sele...          1\n",
      "3272  selena gomez seems like she’s living best life...          1\n",
      "1029    long overdue investment physical infrastructure          2\n",
      "2325  jen married july  ended courtship oct  met ang...          1\n",
      "...                                                 ...        ...\n",
      "2490        harvey weinstein plans sue new york times m          1\n",
      "1194  That arrestee's seriously diseased heart withs...          2\n",
      "1020                  They view effort revise  tax law,          2\n",
      "3619  looking  correction markets‚ä¶ looking crash p...          1\n",
      "142   Amid chaos, spoke publicly violence questioned...          2\n",
      "\n",
      "[4704 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "df = pd.read_excel('../data/data.xlsx')\n",
    "df.to_csv('../data/target_origin51.csv',index=None)\n",
    "\n",
    "# Load files in different encoding formats\n",
    "df_extra_1 = pd.read_csv('../data/extra1.csv',encoding='utf-8')\n",
    "df_extra_2 = pd.read_csv('../data/extra2.csv',encoding='utf-8')\n",
    "df_extra_3 = pd.read_csv('../data/extra3.csv',encoding='utf-8')\n",
    "df_extra_4 = pd.read_csv('../data/extra4.csv',encoding='utf-8')\n",
    "df_extra_5 = pd.read_csv('../data/extra5.csv',encoding='utf-8')\n",
    "# df_extra_6 = pd.read_csv('../data/extra6.csv',encoding='utf-8')\n",
    "# Remove extra spaces in the text\n",
    "df_obj = df_extra_4.select_dtypes(['object'])\n",
    "df_extra_4[df_obj.columns] = df_obj.apply(lambda x: x.str.strip())\n",
    "print(df_extra_4)\n",
    "# set display mode\n",
    "# pd.set_option('display.max_rows', None)\n",
    "# pd.set_option('max_colwidth',50)\n",
    "#print(df_extra_2)\n",
    "# stemming\n",
    "# stemmer = SnowballStemmer(\"english\") # choose the language\n",
    "# define the stopwords\n",
    "stop = stopwords.words('english')\n",
    "# remove the empty data, without this step, we can't go on.\n",
    "df = df.dropna(subset=['Sentence'])\n",
    "# --- debug ----\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==1].count())\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==3].count())\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==5].count())\n",
    "# for sentence: set polit to 1 if with politics bias otherwise 2\n",
    "df['SUBJpolit'] = np.where((df['SUBJpolit'] == 3) | (df['SUBJpolit'] == 5), 2,1)\n",
    "\n",
    "print('------')\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==1].count())\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==2].count())\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==3].count())\n",
    "print(df['SUBJpolit'][df['SUBJpolit']==5].count())\n",
    "# --- debug ----\n",
    "#df['SUBJpolit'] = np.where(df['SUBJpolit'] == 5, 2, 1)\n",
    "\n",
    "res=pd.concat([df_extra_1,df_extra_2,df_extra_3,df_extra_4,df_extra_5],ignore_index=True,axis=0)\n",
    "res = res.drop(columns=['Unnamed: 2'])\n",
    "res.rename(columns={'polit':'SUBJpolit'},inplace = True)\n",
    "print('res',res)\n",
    "# --- save target_origin_sentence\n",
    "\n",
    "target_origin=pd.concat([res,df],ignore_index=True,axis=0)\n",
    "target_origin.to_csv('../data/target_origin571.csv',encoding='utf_8_sig',index=None)\n",
    "\n",
    "print('target_origin',target_origin)\n",
    "target_origin.to_csv('../data/target_origin.csv',index=None)\n",
    "# --- save target_origin_sentence\n",
    "# clear the stopwords\n",
    "# target_without_stopwords = target_origin.drop(columns=['Sentence'])\n",
    "\n",
    "# --- save target_without_stopwords ---\n",
    "target_without_stopwords = target_origin\n",
    "pc = r\"\\d+\\.?\\d*\"\n",
    "target_without_stopwords['Sentence'] = target_origin['Sentence'].apply(lambda w:' '.join([re.sub(pc,\"\",word) for word in str(w).split() if word not in (stop)]))\n",
    "target_without_stopwords = target_without_stopwords.sample(frac = 1)\n",
    "\n",
    "#target_without_stopwords = target_without_stopwords.drop(columns=['Sentence'])\n",
    "#target_without_stopwords.rename(columns={'Sentence_stop':'Sentence'},inplace = True)\n",
    "#target_without_stopwords = target_without_stopwords[['Sentence','SUBJpolit']]\n",
    "target_without_stopwords.to_csv('../data/target_without_stopwords.csv',index=None)\n",
    "\n",
    "print(target_without_stopwords)\n",
    "# --- save target_without_stopwords ---\n",
    "#print(res.columns)\n",
    "#res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "none bias numbers: 3132\n",
      "bias numbers: 1572\n",
      "balanced none bias numbers: 1753\n",
      "                                               Sentence  SUBJpolit\n",
      "2077  trumps pressure drove rocket man reach weaker ...          2\n",
      "2411  however people read harris claim referring off...          2\n",
      "3310  If Republicans detach Trump much, risk alienat...          2\n",
      "1765  north korea long history meaningless negotiati...          2\n",
      "661   makes hike appealing range hikers choose short...          1\n",
      "...                                                 ...        ...\n",
      "505   “a little botox helps smooth forehead lines ea...          1\n",
      "1113  president trump responded brutal murder callin...          1\n",
      "2250      waits day day released relative United States          2\n",
      "2970  hell happy scuttles nuclear agreement starves ...          2\n",
      "35    it’s probably fka twig deal crazy twilight fan...          1\n",
      "\n",
      "[3325 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "# reformat csv\n",
    "t_set = target_without_stopwords[target_without_stopwords['SUBJpolit']==1]\n",
    "f_set = target_without_stopwords[target_without_stopwords['SUBJpolit']==2]\n",
    "b_t_set = target_without_stopwords[target_without_stopwords['SUBJpolit']==1].iloc[0:int(len(t_set)*0.56)]\n",
    "#print(b_t_set)\n",
    "#print(f_set)\n",
    "\n",
    "print('none bias numbers: %s' % len(t_set))\n",
    "print('bias numbers: %s' % len(f_set))\n",
    "print('balanced none bias numbers: %s' % len(b_t_set))\n",
    "b_set = pd.concat( [b_t_set,f_set], axis=0,ignore_index=True)\n",
    "b_set = b_set.sample(frac = 1)\n",
    "\n",
    "print(b_set)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " ...\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]]\n",
      "[[0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " ...\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]\n",
      " [0 0 0 ... 0 0 0]]\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>aaa</th>\n",
       "      <th>aaliyah</th>\n",
       "      <th>aapl</th>\n",
       "      <th>aaron</th>\n",
       "      <th>aaron rodgers</th>\n",
       "      <th>ab</th>\n",
       "      <th>abandoned</th>\n",
       "      <th>abbott</th>\n",
       "      <th>abby</th>\n",
       "      <th>abc</th>\n",
       "      <th>...</th>\n",
       "      <th>zones</th>\n",
       "      <th>zoo</th>\n",
       "      <th>zoom</th>\n",
       "      <th>zoom call</th>\n",
       "      <th>zoom home</th>\n",
       "      <th>zoos</th>\n",
       "      <th>zuckerberg</th>\n",
       "      <th>zymet</th>\n",
       "      <th>µg</th>\n",
       "      <th>μg</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>...</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 20000 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   aaa  aaliyah  aapl  aaron  aaron rodgers  ab  abandoned  abbott  abby  abc  \\\n",
       "0    0        0     0      0              0   0          0       0     0    0   \n",
       "1    0        0     0      0              0   0          0       0     0    0   \n",
       "2    0        0     0      0              0   0          0       0     0    0   \n",
       "3    0        0     0      0              0   0          0       0     0    0   \n",
       "4    0        0     0      0              0   0          0       0     0    0   \n",
       "\n",
       "   ...  zones  zoo  zoom  zoom call  zoom home  zoos  zuckerberg  zymet  µg  \\\n",
       "0  ...      0    0     0          0          0     0           0      0   0   \n",
       "1  ...      0    0     0          0          0     0           0      0   0   \n",
       "2  ...      0    0     0          0          0     0           0      0   0   \n",
       "3  ...      0    0     0          0          0     0           0      0   0   \n",
       "4  ...      0    0     0          0          0     0           0      0   0   \n",
       "\n",
       "   μg  \n",
       "0   0  \n",
       "1   0  \n",
       "2   0  \n",
       "3   0  \n",
       "4   0  \n",
       "\n",
       "[5 rows x 20000 columns]"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import joblib\n",
    "\n",
    "# tokenize document \n",
    "tv=TfidfVectorizer(use_idf=True,smooth_idf=True,encoding='utf-8',ngram_range=(1,2),max_features=20000)\n",
    "fit_tv=tv.fit_transform(b_set['Sentence']).astype('int').toarray()\n",
    "#print(tv.get_feature_names())\n",
    "#print(fit_tv.shape)\n",
    "#print(fit_tv)\n",
    "term_matrix = pd.DataFrame(fit_tv, columns=tv.get_feature_names())\n",
    "\n",
    "# split the train/test dataset \n",
    "X_train,X_test,Y_train,Y_test=train_test_split(fit_tv, b_set['polit'].astype('int').values\n",
    "                                               ,test_size=0.1,random_state = None)\n",
    "# joblib.dump(X_test, '10000X.test')\n",
    "\n",
    "print(X_test)\n",
    "print(X_train)\n",
    "term_matrix.head()\n",
    "\n",
    "#df = df.drop(columns=['ID'])\n",
    "# a = len(df2['SUBJ'][np.where(df2['ID'] == df['ID'][2549])[0]].values)!=0 if df2['SUBJ'][np.where(df2['ID'] == df['ID'][2547])[0]].values[0] else 1\n",
    "\n",
    "# df = df[['ID','Sentence','SUBJindl','SUBJlang','SUBJopin','SUBJsrce','SUBJrhet','SUBJster','SUBJspee','SUBJinspe','SUBJprop','SUBJpolit']].dropna()\n",
    "# df = df.drop(columns=['Sentence'])\n",
    "# df = df.drop(df[df['SUBJsrce']==0].index)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(4500, 20000)\n",
      "[2 1 2 ... 2 2 2]\n"
     ]
    }
   ],
   "source": [
    "X_train\n",
    "Y_train\n",
    "print(X_train.shape)\n",
    "print(Y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.discriminant_analysis import LinearDiscriminantAnalysis\n",
    "from sklearn.svm import LinearSVC\n",
    "from sklearn.datasets import load_iris\n",
    "from sklearn.svm import LinearSVC, SVC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "LinearSVC()"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lsvc=LinearSVC()\n",
    "lsvc.fit(X_train,Y_train.astype('int'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "scrolled": false
   },
   "outputs": [],
   "source": [
    "clf_1 = LinearSVC(loss='hinge').fit(X_train, Y_train)  # possible to state loss='hinge'\n",
    "clf_2 = LinearSVC().fit(X_train, Y_train)  # possible to state loss='hinge'\n",
    "clf_3 = SVC(kernel='linear').fit(X_train, Y_train)\n",
    "\n",
    "score_1 = clf_1.score(X_test, Y_test)\n",
    "score_2 = clf_2.score(X_test, Y_test)\n",
    "score_3 = clf_3.score(X_test, Y_test)\n",
    "\n",
    "\n",
    "score_11 = clf_1.score(X_train, Y_train)\n",
    "score_22 = clf_2.score(X_train, Y_train)\n",
    "score_33 = clf_3.score(X_train, Y_train)\n",
    "\n",
    "print('LinearSVC score %s' % score_1)\n",
    "print('LinearSVC score with hinge loss %s' % score_2)\n",
    "print('SVC score %s' % score_3)\n",
    "print('---------------------')\n",
    "\n",
    "print('LinearSVC score %s' % score_11)\n",
    "print('LinearSVC score with hinge loss %s' % score_22)\n",
    "print('SVC score %s' % score_33)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "-0.340591243942457\n",
      "-0.5272996353001298\n"
     ]
    }
   ],
   "source": [
    "from sklearn.svm import SVR\n",
    "from sklearn.pipeline import make_pipeline\n",
    "from sklearn.preprocessing import StandardScaler\n",
    "import numpy as np\n",
    "regr = make_pipeline(StandardScaler(), SVR(C=1.0, epsilon=0.2))\n",
    "regr.fit(X_train, Y_train)\n",
    "print(regr.score(X_train, Y_train))\n",
    "print(regr.score(X_test, Y_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5004166666666666\n",
      "0.49\n"
     ]
    }
   ],
   "source": [
    "# svm\n",
    "clf = SVC(C=0.8, kernel='linear', gamma=20, decision_function_shape='ovr')\n",
    "clf.fit(X_train, Y_train.ravel())\n",
    "print (clf.score(X_train, Y_train))\n",
    "print (clf.score(X_test, Y_test))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "clf = SVC(C=0.8, kernel='poly', gamma=20, decision_function_shape='ovr')\n",
    "clf.fit(X_train, Y_train.ravel())\n",
    "print (clf.score(X_train, Y_train))\n",
    "print (clf.score(X_test, Y_test))\n",
    "clf = SVC(C=0.8, kernel='rbf', gamma=20, decision_function_shape='ovr')\n",
    "clf.fit(X_train, Y_train.ravel())\n",
    "print (clf.score(X_train, Y_train))\n",
    "print (clf.score(X_test, Y_test))\n",
    "clf = SVC(C=0.8, kernel='sigmoid', gamma=20, decision_function_shape='ovr')\n",
    "clf.fit(X_train, Y_train.ravel())\n",
    "print (clf.score(X_train, Y_train))\n",
    "print (clf.score(X_test, Y_test))\n",
    "from sklearn.metrics import accuracy_score\n",
    "accuracy_score(Y_test.astype('int'),predict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAY4AAAEHCAYAAAC5u6FsAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8vihELAAAACXBIWXMAAAsTAAALEwEAmpwYAAAs4klEQVR4nO3deXhV1b3/8fc3ExmAkAEQCCSoIBVk0ICIoqiVggNDRauiYnsrDleut320anu11Xvba5Vfa2+r10utEw6oOLQOKBUBJ0DCpIhMSoCAQhIgQEIgw/f3xzmEkxAgB3I4gXxez+OTc/Zee5+1E8kna6291zJ3R0REpKFiol0BERE5tig4REQkLAoOEREJi4JDRETCouAQEZGwxEW7AkdDZmam5+TkRLsaIiLHlAULFhS5e9u625tFcOTk5JCXlxftaoiIHFPMbG1929VVJSIiYVFwiIhIWBQcIiISFgWHiIiERcEhIiJhUXCIiEhYFBwiIhKWZvEcx2Gbdjd890W0ayEicvhOOA2GP9iop1SLQ0REwqIWx8E0ckqLiBwPItriMLNhZrbCzFab2d0HKdffzKrMbEzItp+Z2ZdmttTMXjSzxDrH3GFmbmaZkbwGERGpLWLBYWaxwKPAcOBU4GozO/UA5X4PvBeyrRPwb0Cuu/cCYoGrQvZ3Bi4C1kWq/iIiUr9ItjgGAKvd/Rt33wNMAUbWU24C8Cqwuc72OCDJzOKAZGBjyL4/Ar8AtGC6iMhRFsng6ASsD3lfENxWI9iyGA08Hrrd3TcAEwm0KL4FStx9evCYEcAGd19ysA83s/FmlmdmeYWFhUd6LSIiEhTJ4LB6ttVtITwC3OXuVbUONEsj0DrpCnQEUszsWjNLBn4F3HeoD3f3Se6e6+65bdvuN528iIgcpkjeVVUAdA55n0Xt7iaAXGCKmQFkAhebWSUQD6xx90IAM3sNGAQsIRAmS4LHZAELzWyAu38XwWsRE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gX/aYWfd6Vl77GLgyuP9U4LQGnvsKM4sxs5MIrPC2gkB31ti9nwV0CW6vxcyyCSzg9FcCU+c32toM0vyoq0qkcT1BoNtqYXB9k0JgVJ0yjxEYi/gcWAR8DpQ04NwrgNkEpgm/2d3LzewxAuMdXwCVwA3uvjs4hXioIcCdZlYB7ATU4pDDpmnVRY6y4Pof8cFf/CcBM4Du7r4nylUTaRC1OESOvmRgZrA7y4BbFBpyLFGLQ+QgzOxRAisjhvqTuz8VjfqINAUKDhERCYvuqhIRkbAoOEREJCwKDhERCYuCQ0REwvL/AcRC7N0pCNHbAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "# don't use knn\n",
    "from sklearn.neighbors import KNeighborsClassifier\n",
    "import matplotlib.pyplot as plt\n",
    "training_accuracy = []\n",
    "test_accuracy = []\n",
    "neighbors_setting = range(1,7)\n",
    "for i in neighbors_setting:\n",
    "    neigh = KNeighborsClassifier(n_neighbors=i)\n",
    "    neigh.fit(X_train,Y_train)\n",
    "    training_accuracy.append(neigh.score(X_train, Y_train)) \n",
    "    test_accuracy.append(neigh.score(X_test, Y_test))\n",
    "plt.plot(neighbors_setting, training_accuracy, label=\"training accuracy\")\n",
    "plt.plot(neighbors_setting, test_accuracy, label=\"test accuracy\")\n",
    "plt.ylabel(\"Accuracy\")\n",
    "plt.xlabel(\"n_neighbors\")\n",
    "plt.legend()\n",
    "plt.show()\n",
    "#print(training_accuracy)\n",
    "#print(test_accuracy)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n"
     ]
    }
   ],
   "source": [
    "for i in range(2,3):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4778195488721805\n"
     ]
    }
   ],
   "source": [
    "from sklearn.metrics import accuracy_score\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "#predict = neigh.predict(X_test)\n",
    "#print('predict',predict)\n",
    "neigh = KNeighborsClassifier(n_neighbors=3)\n",
    "neigh.fit(X_train,Y_train)\n",
    "        \n",
    "print(neigh.score(X_train,Y_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2 0.0\n",
      "3 0.0\n",
      "4 0.0\n",
      "5 0.5125\n",
      "6 0.0\n",
      "7 0.0\n",
      "8 0.0\n",
      "9 0.0\n"
     ]
    }
   ],
   "source": [
    "from sklearn.ensemble import RandomForestClassifier\n",
    "from sklearn.datasets import make_classification\n",
    "X_train, Y_train = make_classification(n_samples=4000, n_features=30000,\n",
    "                           n_informative=2, n_redundant=0,\n",
    "                           random_state=0, shuffle=True)\n",
    "for i in range(2,10):\n",
    "    clf = RandomForestClassifier(max_depth=i, random_state=0)\n",
    "    clf.fit(X_train, Y_train)\n",
    "    print(i,clf.score(X_test,Y_test))    \n",
    "#print(clf.predict(X_test))\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.965\n"
     ]
    }
   ],
   "source": [
    "print(clf.score(X_train,Y_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df['SUBJ'] = 0\n",
    "pd.options.mode.chained_assignment = None  # default='warn'\n",
    "for j in tqdm(list(df.index)):\n",
    "    df['SUBJ'][j] = df2['SUBJ'][np.where(df2['ID'] == df['ID'][j])[0]].values[0] if len(df2['SUBJ'][np.where(df2['ID'] == df['ID'][j])[0]].values) != 0 else 0\n",
    "df.to_csv('./'+str(j)+'.csv',index=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
